package com.nervenets.shopping.hibernate.dao;

import com.nervenets.general.hibernate.dao.BaseDao;
import com.nervenets.shopping.hibernate.domain.common.Address;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public interface AddressDao extends BaseDao<Address> {
    List<Address> findAllByUserIdAndDeletedOrderByDefDesc(long userId, long deleted);

    @Modifying
    @Transactional
    @Query(value = "update Address SET def = false where userId = :userId ")
    void updateAllAddressDefToFalse(@Param("userId") long userId);

    @Modifying
    @Transactional
    @Query(value = "update Address SET def = :def where id = :addressId ")
    void updateAddressDefStatus(@Param("def") boolean def, @Param("addressId") long addressId);
}
